#include "question.h"
#include "reponse.h"

Question::Question(int idCamp, QObject *parent) :
    QObject(parent)
{
    choixRep = NULL;
    // On récup les infos de la question
    QSqlQuery quest;
    quest.exec("SELECT id_quest, num_quest, intitule_quest, lib_nat FROM questions AS q, natures AS n WHERE n.id_nat = nature AND id_quest = " + QString::number(idCamp) + ";");
    quest.next();
    this->id = quest.value(0).toInt();
    this->num = quest.value(1).toInt();
    this->texte = quest.value(2).toString();
    this->typeQ = quest.value(3).toString();
    QSqlQuery rep;
    rep.exec("SELECT id_rep FROM reponses WHERE question = " + QString::number(this->id) + ";");
    while(rep.next())
    {
        Reponse *uneReponse = new Reponse(rep.value(0).toInt());
        reponses.append(uneReponse);
    }
}

QString Question::getNom() const
{
    return nom;
}
void Question::setNom(QString newNom)
{
    nom = newNom;
}

int Question::getId() const
{
    return this->id;
}
void Question::setId(int newId)
{
    this->id = newId;
}

int Question::getNum() const
{
    return num;
}
void Question::setNum(int newNum)
{
    num = newNum;
}

QString Question::getTexte() const
{
    return texte;
}
void Question::setTexte(QString newTexte)
{
    texte = newTexte;
}

QString Question::getTypeQ() const
{
    return typeQ;
}
void Question::setTypeQ(QString newTypeQ)
{
    typeQ = newTypeQ;
}

Reponse* Question::getChoixRep() const
{
    return choixRep;
}

void Question::setChoixRep(Reponse *newChoixRep)
{
    choixRep = newChoixRep;
}

QList<Reponse*> Question::getReponses() const
{
    return reponses;
}
